package com.ruoyi.zy.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zy.domain.VmeJingfang;
import com.ruoyi.zy.service.IVmeJingfangService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * jingfangController
 * 
 * @author ruoyi
 * @date 2024-04-17
 */
@Controller
@RequestMapping("/zy/jingfang")
public class VmeJingfangController extends BaseController
{
    private String prefix = "zy/jingfang";

    @Autowired
    private IVmeJingfangService vmeJingfangService;

    @RequiresPermissions("zy:jingfang:view")
    @GetMapping()
    public String jingfang()
    {
        return prefix + "/jingfang";
    }

    /**
     * 查询jingfang列表
     */
    @RequiresPermissions("zy:jingfang:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VmeJingfang vmeJingfang)
    {
        startPage();
        List<VmeJingfang> list = vmeJingfangService.selectVmeJingfangList(vmeJingfang);
        return getDataTable(list);
    }

    /**
     * 导出jingfang列表
     */
    @RequiresPermissions("zy:jingfang:export")
    @Log(title = "jingfang", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VmeJingfang vmeJingfang)
    {
        List<VmeJingfang> list = vmeJingfangService.selectVmeJingfangList(vmeJingfang);
        ExcelUtil<VmeJingfang> util = new ExcelUtil<VmeJingfang>(VmeJingfang.class);
        return util.exportExcel(list, "jingfang数据");
    }

    /**
     * 新增jingfang
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存jingfang
     */
    @RequiresPermissions("zy:jingfang:add")
    @Log(title = "jingfang", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VmeJingfang vmeJingfang)
    {
        return toAjax(vmeJingfangService.insertVmeJingfang(vmeJingfang));
    }

    /**
     * 修改jingfang
     */
    @RequiresPermissions("zy:jingfang:edit")
    @GetMapping("/edit/{jingfangId}")
    public String edit(@PathVariable("jingfangId") Long jingfangId, ModelMap mmap)
    {
        VmeJingfang vmeJingfang = vmeJingfangService.selectVmeJingfangByJingfangId(jingfangId);
        mmap.put("vmeJingfang", vmeJingfang);
        return prefix + "/edit";
    }

    /**
     * 修改保存jingfang
     */
    @RequiresPermissions("zy:jingfang:edit")
    @Log(title = "jingfang", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VmeJingfang vmeJingfang)
    {
        return toAjax(vmeJingfangService.updateVmeJingfang(vmeJingfang));
    }

    /**
     * 删除jingfang
     */
    @RequiresPermissions("zy:jingfang:remove")
    @Log(title = "jingfang", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(vmeJingfangService.deleteVmeJingfangByJingfangIds(ids));
    }
}
